﻿<phone:PhoneApplicationPage x:Class="dIRca.MainPage"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
                            xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                            xmlns:blend="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                            xmlns:command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP7"
                            xmlns:contrib="clr-namespace:WP7Contrib.View.Controls;assembly=WP7Contrib.View.Controls"
                            xmlns:behaviors="clr-namespace:WP7Contrib.View.Controls.Behaviors;assembly=WP7Contrib.View.Controls"
                            mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                            SupportedOrientations="PortraitOrLandscape"
                            Orientation="Portrait"
                            shell:SystemTray.IsVisible="True"
                            DataContext="{Binding MainViewModel, Source={StaticResource Locator}}">

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <blend:Interaction.Triggers>
            <blend:EventTrigger EventName="Loaded">
                <command:EventToCommand Command="{Binding LayoutRootCommand}" CommandParameter="{Binding ElementName=LayoutRoot}" PassEventArgsToCommand="True"/>
            </blend:EventTrigger>
        </blend:Interaction.Triggers>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <controls:Pivot x:Name="PivotControl"
                Title="{Binding PageTitle}"
                ItemsSource="{Binding Pages}"
                SelectedItem="{Binding SelectedPage, Mode=TwoWay}"
                HeaderTemplate="{StaticResource SmallPivotHeaderTemplate}"
                Style="{StaticResource SmallPivotStyle}">
                <controls:Pivot.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <TextBlock x:Name="textBlockTopic" Text="{Binding Model.Topic}" Grid.Row="0" TextWrapping="Wrap" />
                            <ListBox x:Name="listBoxMessages"
                                     Padding="2"
                                     ItemsSource="{Binding Messages.View}"
                                     ItemTemplate="{StaticResource MessagesTemplate}"
                                     SelectedItem="{Binding SelectedMessage}"
                                     SelectionChanged="MessagesSelectionChanged"
                                     Grid.Row="1" />
                        </Grid>
                    </DataTemplate>
                </controls:Pivot.ItemTemplate>
                <blend:Interaction.Triggers>
                    <blend:EventTrigger EventName="SelectionChanged">
                        <command:EventToCommand Command="{Binding SelectionChangedCommand}" PassEventArgsToCommand="True" />
                    </blend:EventTrigger>
                </blend:Interaction.Triggers>
            </controls:Pivot>
            <Grid Grid.Row="1">
                <TextBox 
                    x:Name="textBoxSendMessage"
                    Text="{Binding SendBuffer, Mode=TwoWay}"
                    KeyDown="textBoxSendMessage_KeyDown"
                    InputScope="Chat"
                    TextWrapping="Wrap" />
            </Grid>
        </Grid>
    </Grid>

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" Opacity="1">
            <shell:ApplicationBarIconButton
                x:Name="connectIcon"
                IconUri="/icons/appbar.download.rest.png"
                Text="Connect" />
            <shell:ApplicationBarIconButton
                x:Name="disconnectIcon"
                IconUri="/icons/appbar.close.rest.png"
                Text="Disconnect" />
            <shell:ApplicationBarIconButton
                x:Name="connectionsIcon"
                IconUri="/icons/appbar.folder.rest.png"
                Text="Connections" />
            <shell:ApplicationBarIconButton
                x:Name="settingsIcon"
                IconUri="/icons/appbar.feature.settings.rest.png"
                Text="Settings"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem x:Name="menuItemAbout" Text="About"/>
                <shell:ApplicationBarMenuItem x:Name="menuItemScreenshot" Text="Screenshot" />
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>
    <blend:Interaction.Behaviors>
    	<behaviors:ApplicationBarIconButtonCommand TextKey="Connect" CommandBinding="{Binding ConnectCommand}" Icon="/icons/appbar.download.rest.png" Text="Connect" />
    	<behaviors:ApplicationBarIconButtonCommand TextKey="Disconnect" CommandBinding="{Binding DisconnectCommand}" Icon="/icons/appbar.close.rest.png" Text="Disconnect" />
    	<behaviors:ApplicationBarIconButtonCommand TextKey="Connections" CommandBinding="{Binding ConnectionsListCommand}" Text="Connections" Icon="/icons/appbar.folder.rest.png" />
    	<behaviors:ApplicationBarIconButtonCommand TextKey="Settings" CommandBinding="{Binding SettingsCommand}" Icon="/icons/appbar.feature.settings.rest.png" Text="Settings" />
    	<behaviors:ApplicationBarMenuItemCommand TextKey="About" CommandBinding="{Binding AboutCommand}" Text="About" />
        <behaviors:ApplicationBarMenuItemCommand TextKey="Screenshot" CommandBinding="{Binding ScreenshotCommand}" Text="Screenshot" />
    </blend:Interaction.Behaviors>
</phone:PhoneApplicationPage>